var page = 1;
var rows = 10;
$(function (){
    getList();
    
    $(".add_news").on('click',function (){
        var adContent=$(".neSc").val();
        if(adContent==""){
            zeroModal.alert("请添加文章来源");
            return;
        }
        $.ajax({
            url:baseNews+"/api/data/sys/add/news/source/?source="+adContent,
            success:function (res){
                if(res.code==0){
                    location.reload();
                }else{
                    zeroModal.alert(res.message);
                }
            }
        })
    })
})
function getList() {
    $.ajax({
        url: baseNews + "/api/data/sys/news/source/list?page=" + page + "&rows=" + rows,
        type: "get",
        data: {},
        success: function (res) {
            console.log(res, 666);
            if (res.code == 0) {
                var result = res.data;
                var list = result.list;
                console.log(list, 9999)
                var html = "";
                $("#page").paging({
                    pageNo: page,
                    totalPage: result.totalpage,
                    totalSize: result.totals,
                    callback: function (num) {
                        page = num;
                        getList();
                    }
                })
                $(".pd_bx").empty();
                var html="";
                $(list).each(function (index, key) {
                    //var state = key;
                    //console.log(state,123);
                    html+=`<tr>
                        <td >
							<input type="checkbox" oid="${key.id}" class="arc_isc"/>
						</td>
                        <td>${key.id}</td>
                        <td>${key.name}</td>
                    </tr>`;
                    
                })
                $(".pd_bx").append(html);
            }
        }
    })
    //分页

}
$(function (){
    $('.delNesF').click(function () {
		var numCount = 0;
		var ids = '';
		$(".arc_isc").each(function (index, key) {
			if ($(this).prop("checked") == true) {
				numCount++;
				ids = ids + $(this).attr("oid") + ',';
			}
        })
        ids = ids.substring(0, ids.length - 1);
		console.log(numCount, 555);
		if (numCount >= 1) {
			//进行下一步
			var json = {}
			var result = JSON.stringify(json);
			zeroModal.confirm("确定要删除该来源吗？", function () {
				//置顶确认请求数据
				$.ajax({
					url: baseNews + "/api/data/sys/remove/news/source/" + ids,
					type: "get",
					data:{},
					success: function (res) {
						if (res.code == 0) {
							location.reload();
						} else {
							zeroModal.alert('删除失败');
						}
					}
				})
			});
		} else {
			//遮罩层提示
			zeroModal.alert('请选择至少一条来源删除');

		}
	})
})